﻿<%@ WebHandler Language="C#" Class="list" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class list : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        string query = HttpContext.Current.Request.Params["category_id"];



        if (string.IsNullOrEmpty(query))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }



        var code = 1;
        var msg = "商城分类商品";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {
            var children = bll.S_Classs.Where(n => n.SCpareID == 0);

          ArrayList listjson = new ArrayList();
            foreach (var xxx in children) 
                {
                
                   var result = bll.S_Goods.Where(p => p.IsLock != true);//全部.ToList();
            var _myresult = result.ToList();



            List<progood> list = new List<progood>();
            foreach (var x in _myresult)
            {
                progood mygood = new progood();
                mygood.id = x.GID;
                mygood.type = "normal";
                mygood.title = x.GName;
                mygood.image = methods.GetImgs(x.GImg)[0].ToString();
                mygood.price =Convert.ToDecimal(x.GPriceYJ);
                mygood.sales = x.GSales;
                list.Add(mygood);
            };
            listjson.Add(new {
                description = "",
                id = 11,
                image = "https://api.7wpp.com/uploads/20201209/c391f225123eb7addd5e971cc2b5d345.png",
                name = "美食酒水",
                pid = 1,
                type = "",
                weigh = 0,
                goods =list});

                
                }

         

            context.Response.Write(JsonConvert.SerializeObject(new { code,msg,time,data=listjson}));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }

    public bool IsReusable {
        get {
            return false;
        }
    }
    public class progood
    {
        public int id { get;  set; }
        public string type { get; set; }
        public string title { get; set; }
        public string image { get; set; }
        public decimal price { get; set; }
        public int? sales { get; set; }

    }


}